home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
yoono-links.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
5KB
|
145 lines
var yoonoLinks = {
init : function () {
this.bundle = document.getElementById("yoono-links-bundle");
// Init menuitems states
this.updateMenus();
this.icon = document.getElementById("yoono-links-icon");
this.icon.setAttribute("status",YOONO_PREFS.get("highlight.enable")?"enabled":"disabled");
this.icon.setAttribute("tooltiptext",this.bundle.getString("yoono-links.loading"));
// Watch for yoolink flash loading
yoono.main.getYServices().observer.addObserver(this,"yoolink.*");
// Watch for tab change and website loading in order to display secured icon
var container = gBrowser.tabContainer;
this.tabListener=function(){yoonoLinks.onTabSelect();};
container.addEventListener("TabSelect", this.tabListener, false);
this.tabLoadListener=function(e){yoonoLinks.onTabLoad(e);};
gBrowser.addEventListener("load", this.tabLoadListener, true);
var contextMenu = document.getElementById("contentAreaContextMenu");
if (contextMenu)
contextMenu.addEventListener("popupshowing", yoonoLinks.onContextShow, false);
},
uninit : function () {
yoono.main.getYServices().observer.removeObserver(this,"yoolink.*");
var container = gBrowser.tabContainer;
container.removeEventListener("TabSelect", this.tabListener, false);
gBrowser.removeEventListener("load", this.tabLoadListener, true);
},
updateMenus : function () {
// Update menu in statusicon
var menu = document.getElementById("yoono-links-menu");
var items = menu.getElementsByTagName("menuitem");
for(var i=0; i<items.length; i++) {
var item=items[i];
item.setAttribute("checked",YOONO_PREFS.get("highlight."+item.getAttribute("pref"))?"true":"false");
}
// Update menu in main button
var menu = document.getElementById("yoono-links-menu-main-button");
var items = menu.getElementsByTagName("menuitem");
for(var i=0; i<items.length; i++) {
var item=items[i];
item.setAttribute("checked",YOONO_PREFS.get("highlight."+item.getAttribute("pref"))?"true":"false");
}
},
onTabSelect : function () {
var browser = gBrowser.selectedTab.linkedBrowser;
var isSecured=browser.contentDocument.location.href.match(/^https:/);
this.icon.setAttribute("secured",isSecured?"true":"false");
if (isSecured) {
this.icon.setAttribute("tooltiptext",this.bundle.getString("yoono-links.https"));
} else {
this.icon.setAttribute("tooltiptext","");
}
},
onTabLoad : function (event) {
if (event.originalTarget instanceof HTMLDocument) {
var doc = event.originalTarget;
if (event.originalTarget.defaultView.frameElement) {
// Frame within a tab was loaded.
return;
}
this.onTabSelect();
}
},
observe : function (topic, param) {
if (topic=="yoolink.flash-loaded") {
if (param==true) {
this.icon.removeAttribute("loading");
this.icon.setAttribute("tooltiptext","");
} else {
this.icon.setAttribute("tooltiptext",this.bundle.getString("yoono-links.flash"));
}
} else if (topic=="yoolink.enable") {
this.icon.setAttribute("status",param?"enabled":"disabled");
}
},
action : function (item) {
this._setPref("highlight."+item.getAttribute("pref"),item.getAttribute("checked")=="true");
},
toggle : function () {
this._setPref("highlight.enable",!YOONO_PREFS.get("highlight.enable"));
},
onContextShow : function (event) {
var search = document.getElementById("yoono-links-context");
var selectedText = getBrowserSelection(16);
search.hidden = selectedText&&selectedText.length>0?false:true;
if (!selectedText)
return false;
if (selectedText.length > 15)
selectedText = selectedText.substr(0,15) + "...";
search.label=yoonoLinks.bundle.getFormattedString("yoono-links.context-menu", [selectedText]);
},
onContextClick : function () {
var selectedText = getBrowserSelection(32);
if (selectedText) {
var contextMenu = document.getElementById("contentAreaContextMenu");
// Compute a "viewport" position
var eventData = {
x: contextMenu.boxObject.x-gBrowser.mCurrentBrowser.boxObject.x+gBrowser.contentWindow.scrollX,
y: contextMenu.boxObject.y-gBrowser.mCurrentBrowser.boxObject.y+gBrowser.contentWindow.scrollY,
keywords : selectedText,
windowId : YOONO_YEXTIF.getWindowId(window)
};
yoono.main.getYServices().observer.notifyObservers("yoolink.search",eventData);
}
},
_setPref : function (pref, value) {
YOONO_PREFS.set(pref,value);
if (pref == "highlight.enable") {
this.icon.setAttribute("status",value?"enabled":"disabled");
yoono.main.getYServices().observer.notifyObservers("yoolink.enable",value);
}
this.updateMenus();
}
};
function waitForYServices() {
if (yoono && yoono.main && yoono.main.getYServices() && yoono.main.getYServices().observer)
return yoonoLinks.init();
window.setTimeout(waitForYServices,500);
}
window.addEventListener("load", waitForYServices, false);
window.addEventListener("unload", function() { yoonoLinks.uninit(); }, false);